//
//  RootViewController.m
//  UI2_设计模式课堂练习
//
//  Created by dllo on 15/11/9.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"

#warning 回收键盘第二步 签协议
@interface RootViewController ()<UITextFieldDelegate>

@property (nonatomic, retain) UITextField *passwdTF;
@property (nonatomic, retain) UITextField *userTF;

@end

@implementation RootViewController




- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
//    UIImage *image = [UIImage imageNamed:@"/Users/dllo/Desktop/DLS151034/UI1_View_Label/UI1_View_Label课后作业/HW1_2/HW1_2/1131907198420455d6o.jpg"];
//    self.view.layer.contents = (id)image.CGImage;
    
    // 用户名
    UILabel *userL = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 60, 30)];
//    userL.backgroundColor = [UIColor redColor];
    userL.text = @"用户名";
    [self.view addSubview:userL];
    [userL release];
    
    self.userTF = [[UITextField alloc] initWithFrame:CGRectMake(userL.frame.origin.x + userL.frame.size.width + 20, userL.frame.origin.y, [UIScreen mainScreen].bounds.size.width - (userL.frame.origin.x + userL.frame.size.width + 10) - userL.frame.origin.x, userL.frame.size.height)];
    self.userTF.placeholder = @"请输入用户名";
#warning 回收键盘第一步 设置代理人
    self.userTF.delegate = self;
    self.userTF.clearButtonMode = UITextFieldViewModeAlways;
    self.userTF.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:self.userTF];
    [_userTF release];
    
    // 密码
    UILabel *passwdL = [[UILabel alloc] initWithFrame:CGRectMake(userL.frame.origin.x, userL.frame.origin.y + userL.frame.size.height + 20, userL.frame.size.width, userL.frame.size.height)];
    passwdL.text = @"密码";
    [self.view addSubview:passwdL];
    [passwdL release];
    
    self.passwdTF = [[UITextField alloc] initWithFrame:CGRectMake(self.userTF.frame.origin.x, passwdL.frame.origin.y, self.userTF.frame.size.width, self.userTF.frame.size.height)];
    self.passwdTF.placeholder = @"请输入密码";
    self.passwdTF.delegate = self;
    self.passwdTF.clearButtonMode = UITextFieldViewModeAlways;
    self.passwdTF.borderStyle = UITextBorderStyleRoundedRect;
    self.passwdTF.secureTextEntry = YES;
    [self.view addSubview:self.passwdTF];
    [_passwdTF release];
    
    // Button
    UIButton *loginB = [UIButton buttonWithType:UIButtonTypeCustom];
    loginB.frame = CGRectMake(userL.frame.origin.x, passwdL.frame.origin.y + passwdL.frame.size.height + 200, 50, userL.frame.size.height);
    [loginB addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    // 前景图片与背景图片的区别:
    // 1,前景图片保留原来图片尺寸,背景图片填充到button尺寸
    // 2,若有标题,前景图片将标题挤到一边,背景图片置于标题下面
    // 应用场景:前景图片可以应用于图片较小但需要较大生效范围的情况
    
    // 设置前景图片
    //UIImage管理图片的类
    [loginB setImage:[UIImage imageNamed:@"BtnOn.png"] forState:UIControlStateNormal];
    // 选择状态下
    [loginB setImage:[UIImage imageNamed:@"BtnOff.png"] forState:UIControlStateSelected];
    
    // 设置背景图片
//    [loginB setBackgroundImage:[UIImage imageNamed:@"BtnOn.png"] forState:UIControlStateNormal];
    
    [self.view addSubview:loginB];
    
    
    
    
    
    
}
#warning 回收键盘第三步 实现协议方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    NSLog(@"点击return按键触发");
    
#warning 回收键盘第四步 取消第一响应者
    
//    [self.userTF resignFirstResponder];
    
    if (textField == self.userTF) {
        [self.passwdTF becomeFirstResponder];
    }
    if (textField == self.passwdTF) {
        [textField resignFirstResponder];
    }
    return YES;
    
}


- (void)buttonAction:(UIButton *)sender
{
    // button选择状态的判断依据selected属性,但此属性需要手动置位
    sender.selected = !sender.selected;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
